<template>
  <div>
    <goga-header title="修改密码">
      <div slot="left">
        <span @click="goBack">
          <icon symbol="back"> </icon>
        </span>
      </div>
    </goga-header>
    <div class="form-wrapper">
      <form>
        <section class="form-group">
          <input type="password" placeholder="请输入旧的密码" v-model.trim="model.oldPwd">
        </section>
        <section class="form-group">
          <input v-if="!showPwd" type="password" placeholder="请输入新的密码" v-model.trim="model.newPwd">
          <input v-if="showPwd" type="text" placeholder="请输入新的密码" v-model.trim="model.newPwd">
          <div class="xxcf-switch">
            <input class="xxcf-switch-core" type="checkbox" id="isDefault" v-model="showPwd">
          </div>
        </section>
        <div class="link" >&nbsp;</div>
        <div class="btn-group">
          <button class="btn btn-default" @click.prevent="submit" v-bind:disabled="disabled">确认修改</button>
        </div>
      </form>
    </div>
  </div>
</template>

<script lang="babel">
  import gogaHeader from '@components/goga-header'
  import Icon from '@components/icon'
  import {validate} from '@utils'
  import api from '@api'
  import {mapGetters} from 'vuex'
  import {cookie} from '@utils'
  export default {
    components: {
      gogaHeader,
      Icon
    },
    computed: {
      ...mapGetters({
        isLogin: 'global/user/isLogin'
      })
    },
    data() {
      return {
        loginDisabled: false,
        loginForm: {},
        model: {
          newPwd:'',
          oldPwd: ''
        },
        showPwd: false,
        disabled: false,
        codPic: 'http://www.gogagoga.cc/api/verCode/tpcode.ashx'
      }
    },
    async mounted() {
    },
    methods: {
      goBack() {
        this.$router.go(-1);
      },
      async submit() {
        if(!validate.minLength(this.model.oldPwd, 6)) {
          this.$store.dispatch('global/toast', '请输入旧密码');
          return false;
        }
        if(!validate.minLength(this.model.newPwd, 6)) {
          this.$store.dispatch('global/toast', '请输入新密码');
          return false;
        }
        this.disabled = true;
        let {data: {StatusCode, Status}} = await api.post('api/v1/UserInfo/changePwd.ashx', this.model)
        if (StatusCode === '200') {
          this.$store.dispatch('global/toast', '密码修改成功');
          this.goBack()
        } else {
          this.$store.dispatch('global/toast', Status);
        }
        this.disabled = false;
      }
    }
  }
</script>

<style lang="less">
  @import "index.less";
</style>
